package mn.more.mock.gen;

import java.io.IOException;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author $Author: mikeliucc $
 * @version $Revision: 119 $
 */
public class NumberGenerator extends GeneratorBase {

	private NumberFormat format;
	private int maxInt = 100;

	public NumberFormat getFormat() { return format; }

	public void setFormat(NumberFormat format) { this.format = format; }

	public int getMaxInt() { return maxInt; }

	public void setMaxInt(int maxInt) { this.maxInt = maxInt; }

	public List<String> generate() throws IOException {
		List<String> numbers = new ArrayList<String>(max);

		Random rand = new Random(System.currentTimeMillis());
		for (int i = 0; i < max; i++) {
			double number = rand.nextInt(maxInt - 1) + rand.nextDouble();
			String numString = format.format(number);
			if (isDataUsable(numbers, numString)) {
				numbers.add(numString);
			} else {
				i--;
			}
		}

		return numbers;
	}
}
